home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGMISC
/
FPCDOCS.LZH
/
DOSINTFC.DOC
< prev
next >
Wrap
Text File
|
1988-06-01
|
9KB
|
229 lines
VII. DOS INTERFACE
Forth is a language with an operating system packed in. It
provides a complete programming environment so that a user can
write, test and debug substantial programs completely inside of
this environment. When Chuck Moore started developing Forth, the
operating systems were primitive, and often got in the way,
preventing the user to exploit the full capability of the hardware
underneath the operating system. His solution, which has been
adopted by most earlier Forth implementations, was to eliminate
the operating system completely and incorporate all essetial
function of the operating system into Forth. BLOCK was invented
to access mass storage directly, and it allows Forth to use
different magnetic storage media very efficiently and quite
transparent to the user.
However, using BLOCK's imposes many restrictions on the style of
programming in Forth. The most apparent restriction is on the
editor, which handles text in fixed 1024 byte chunks. It also
makes Forth incompatible with other programming environments.
In the good old days of minicomputers and microcomputers,
compatibility was among the least of concerns because there were
so many of them. None of them were compatible in hardware nor in
software. In the confusion, Forth was able to offer an universal
solution, and was ported easily to every machine in sight. It is
very sad that these bygone days were no more. In the field of
microcomputers and personal computers, Big Blue and Not-So-Big Red
have established certain common practices, if not standards.
Whether we like them or not, DOS and MAC prevail as the
environments we are condemned to live for the next few years.
After that, we will all be sentenced for life under UNIX if we can
ever escape from C.
It is thus very important that Forth should take advantage of
these less than optimized operating system in areas where
convenience and compatibility are useful and cost effective.
Forth can be then used to arrive at the optimized solutions which
demands the best of performance and code compaction. F-PC tries to
exploit the DOS environment to its practical limit in adopting the
sequential file structure for mass storage and providing a smooth
and convenient path to all the utility available in DOS and OS2
when it becomes readily available. All DOS and BIOS calls are
readily available.
1. SYSTEM INTERRUPTS AND BIOS CALLS
BIOS (Basic Input Output System) is a set of subroutines stored in
the Read-Only Memory in PC. These subroutines provide the most
elementary services for the operating system to use the resources
in PC, such as the keyboard, the display, the disk drives, and the
printer.
To invoke any of these service subroutines, a software interrupt
instruction INT must be executed at the machine level. This
interrupt instruction transfers the control to the proper service
routine via an interrupt vector table in the memory area 0:0 to
0:3FFH. Parameters are sent to the service routine in one or more
registers in the CPU. Results if any are returned in the
registers. For available BIOS services and their functional
specifications, one must consult the IBM Hardware Reference Manual
for the specific machine or any reasonable good book on MSDOS.
F-PC itself does not provide high level tools to do software
interrupts. However, it does uses BIOS service to handle keyboard
input, screen and printer output. Since most of these words were
coded in assembly, they invoke INT instructions directly. For
example, to receive a character from the keyboard:
CODE BIOSKEY ( -- char )
BEGIN
MOV AH, # 0
INT 16
CMP AX, # 0
0<> UNTIL
MOV BIOSKEYVAL AX
1PUSH
END-CODE
Other important software interrupts are: INT 5 for printer, INT 6
for viedo display, INT 19 for diskette drive, and INT 33 for DOS
services.
2. DOS SERVICE CALLS
INT 33 invokes the DOS services which cover a wide range of very
interesting functions which are not in the BIOS ROM, but loaded
into the RAM memory when DOS is booted. F-PC uses the DOS services
very extensively and a set of words are defined to facilitate
their uses.
BDOS ( data function -- n )
This service emulates the CP/M BDOS call protocol, which requires
a function number and some data. The number returned on the stack
is zero always, so that it is compatible with the BDOS function
implemented in F83.
When a service call requires more input and/or output parameters,
F-PC give you the following choices:
BDOS2 ( CX DX AX -- CX DX AX )
OS2 ( CX DX AX -- CX DX AX )
OS2 is identical to BDOS2 with the sole purpose to impress people
in the three piece suites.
XFDOS ( DX CX BX AX ES DS -- CX BX AX CY )
XFDOS is needed to allow DOS services to access memory above the
64K byte code/data segment.
3. THE DOS SHELL
The interface to DOS occurs at several levels. In this section we
will discuss the interface to the DOS commands as opposed to the
DOS system calls.
It is convenient to be able to issue DOS commands from within F-PC.
This avoids having to leave F-PC to do the normal housekeeping
things that are regular occurrences in a DOS based computer. In
line with this, F-PC implements several commands:
$sys ( countedstring --- f1 )
Pass the countedstring to COMMAND.COM as a command line. A shell
is spawned in the process with the "/c" parameter included so
COMMAND.COM terminates on completion of the command line. If a
NULL string is passed then the DOS shell will be spawned for you
to enter one or several command lines. You can then return to
Forth by typing EXIT <enter>.
sys ( | command --- )
Accept the command line following SYS as a DOS command line.
` ( command --- )
A pseudonym for SYS. See also SYS.
These words allow performing almost any DOS command line operation
you would want to do. To make things even more convenient,
several additional words have been coded which use the $SYS word
for specific functions. They are as follows:
DIR FORMAT FTYPE DEL CHDIR COPY REN RD MD PATH
A: B: C: D: E:
These commands may be used as they are in DOS. The word FTYPE
replaces the DOS word TYPE for obvious reasons. If you press
Control-C, or Control-Break during the execution of any of the
above words, operation will abort back to Forth.
SYS or ` can be given without a DOS command. In this case you
enter the COMMAND.COM shell and you will see the familiar A> or
equivalent DOS prompt. You can execute any DOS commands or other
COM or EXE files. After you are through with DOS, type EXIT will
return you back to F-PC. You can switch very conveniently back and
forth among Forth, DOS and any other application.
4. BATCH COMMANDS
F-PC allow commands to be passed to Forth on the DOS command line
in the following manner:
C> F-PC <filename> <forth words> <enter>
This example illustrates how you can start F-PC with a specified
file name, and perform commands on the file. An example of how
this might be used is as follows:
C> F-PC BANNER OK <enter>
Here we are starting F-PC with the file BANNER.SEQ, and then
performing OK to compile the file. Another way to use command
line parameters is:
C> F-PC - <forth words> <enter>
Here we are starting F-PC, followed by a dash "-" to tell F-PC we
are not opening a file, then telling F-PC to perform the Forth
words following the "-". Here is an example:
C> F-PC - FIX DIR <enter>
This example starts up F-PC without a file and tells F-PC we want to
fix the word DIR. It will locate the word DIR and start up the
editor with the cursor located on the first line of the DIR
definition.
You can get to batch files now, as you can see many types of
commands could be given to F-PC on the command line. Here are the
contents of the PMETA.BAT:
F-PC - FLOAD META86
This single line batch file re-meta-compiles the F-PC kernel file
and re-creates the KERNEL.COM file. A similar batch file is
provided to extend the system.
The one caution on batch files is you must not place commands on
the command line which cause the command line to be interpreted
again. The words HELLO and COLD are such words, and should not be